package com.atguigu.controller;


import com.atguigu.pojo.DeliveryList;
import com.atguigu.pojo.User;
import com.atguigu.service.DeliveryService;
import com.atguigu.service.impl.DeliveryServiceImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;
import java.util.List;

@WebServlet("/delivery/List" )
public class DeliveryListController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        User user = (User) session.getAttribute("Session_User");
            //用户已登录
            DeliveryService deliveryService = new DeliveryServiceImpl();
            //拿到对应用户的快递信息，存在List集合中
            List<DeliveryList> deliveries = deliveryService.getAllDeliverysById(user.getId());
            //将快递信息动态渲染到页面上展示
            req.setAttribute("deliveries",deliveries);
            req.getRequestDispatcher("/list.jsp").forward(req,resp);

    }
}
